package cc.customer.saleHelp.services.Impl;

import cc.customer.common.domain.ResponseBo;
import cc.customer.common.service.impl.BaseService;
import cc.customer.common.utils.DateUtil;
import cc.customer.saleHelp.dao.CSaleCustomerMapper;
import cc.customer.saleHelp.dao.CsalePlanMapper;
import cc.customer.saleHelp.domain.CSaleCustomer;
import cc.customer.saleHelp.domain.CsalePlan;
import cc.customer.saleHelp.services.CsaleCustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

@Service
public class CsaleCustomerServiceImpl extends BaseService<CSaleCustomer> implements CsaleCustomerService {

    @Autowired
    private CSaleCustomerMapper customerMapper;

    @Autowired
    private CsalePlanMapper planMapper;


    @Override
    public List<CSaleCustomer> selectPlanCus(CSaleCustomer customer){
        try {
            Example example = new Example(CSaleCustomer.class);
            example.createCriteria().andEqualTo("cpPid",customer.getCpPid());
            List<CSaleCustomer> list = this.selectByExample(example);
            return list;
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ArrayList<>();
    }


    @Override
    public ResponseBo newSendPlan(CSaleCustomer customer){
        try {
            customer.setCpTime(DateUtil.getCurrentDate("yyyy-MM-dd HH:mm:ss"));
            customerMapper.updateCus(customer);
            //更新计划执行状态
            planMapper.updateDetail(customer.getCpPid());
            return ResponseBo.ok();
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResponseBo.error();
    }

    @Override
    public ResponseBo updateByApp(CSaleCustomer cus){
        try {
            cus.setCpTime(DateUtil.getCurrentDate("yyyy-MM-dd HH:mm:ss"));
            customerMapper.updateByApp(cus);
            planMapper.updateDetail(cus.getCpPid());
            return ResponseBo.ok();
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResponseBo.error();
    }
}
